#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e5+10;
int a[maxn];
int ans[maxn];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		int cnt = 0;
		scanf("%d",&n);
		for(int i = 0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		ans[cnt++] = a[0];
	//	printf("****%d\n",a[0]);
		for(int i = 1;i<n;)
		{
			if(a[i]>a[i-1])
			{
				while(a[i]>a[i-1]&&i<n)
				{
					i++;
				}
				a[cnt++] = a[i-1];

			}
			else
			{
				while(a[i]<a[i-1]&&i<n)
				{
					i++;
				}
				a[cnt++] = a[i-1];
			}
		}
		printf("%d\n",cnt);
		for(int i = 0;i<cnt;i++)
		{
			if(i==0) printf("%d",a[i]);
			else printf(" %d",a[i]);
		}
		printf("\n");
	}
}
